package com.ht.safe.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.hibernate.annotations.Index;

import javax.persistence.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 薄成文 13-7-19 上午11:08
 * To change this template use File | Settings | File Templates.
 */
public class Area {
    /**
     * 名称
     */
    @Index(name="idx_area_name")
    @Column(name="inner_code", unique = true, nullable = false)
    private String name;

    /**
     * 编号, 由用户指定
     */
    @Index(name="idx_area_code")
    private String code;

    /**
     * 内部编号，由系统分配生成，用于控制器执行逻辑判断
     */
    @Column(name="inner_code", unique = true)
    private String innerCode;

    @Column(name="group_name")
    private String groupName;

    /**
     * 父节点
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    @JSONField(serialize = false)
    private Area parent;


    /**
     * 该节点下的的所有子节点
     */
    @OneToMany(mappedBy = "parent", orphanRemoval=true)
    private List<Area> children;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getInnerCode() {
        return innerCode;
    }

    public void setInnerCode(String innerCode) {
        this.innerCode = innerCode;
    }

    public Area getParent() {
        return parent;
    }

    public void setParent(Area parent) {
        this.parent = parent;
    }

    public List<Area> getChildren() {
        return children;
    }

    public void setChildren(List<Area> children) {
        this.children = children;
    }
}
